package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.ElderFamilyDto;
import com.zzyl.nursing.dto.FamilyDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.mapper.FamilyMemberMapper;
import com.zzyl.nursing.service.impl.FamilyMemberServiceImpl;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 *
 * @author syl
 * @date 2025-05-30  member/user/login
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private FamilyMemberMapper familyMemberMapper;

    @PostMapping("/login")
    @ApiOperation("老人家属的登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo =  familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyDto familyDto){
        familyMemberService.bindingFamily(familyDto);
        return success();
    }

    @GetMapping("/my")
    @ApiOperation("获取当前登录用户的家人信息")
    public AjaxResult getMyFamily(){
        List<ElderFamilyDto> list = familyMemberService.getMyFamily();
        return success(list);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页获取当前登录用户的家人信息")
    public AjaxResult listByPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        Long userId = UserThreadLocal.get();
        List<FamilyMemberElderVo> list = familyMemberService.getFamilyList(userId,pageNum,pageSize);
        return success(list);
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询设备属性")
    public AjaxResult queryServiceProperties(@PathVariable String iotId){
        return success(familyMemberService.queryServiceProperties(iotId));
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天查询设备数据")
    public AjaxResult queryDeviceDataListByDay(@RequestBody DeviceDataDto dto){
        return success(familyMemberService.queryDeviceDataListByDay(dto));
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按天查询设备数据")
    public AjaxResult queryDeviceDataListByWeek(@RequestBody DeviceDataDto dto){
        return success(familyMemberService.queryDeviceDataListByWeek(dto));
    }
}
